package com.ss.android.article.base.feature.detail.model;

import com.bytedance.common.utility.Logger;
import com.ss.android.action.a.a.Comment;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.model.DownloadAppAd;

import org.json.JSONException;
import org.json.JSONObject;

public final class CommentWrapper {
    public int cellType;
    public long id;
    public Comment mComment;
    public int d;
    public int e;
    public MixedAdsData mMixedAdsData;
    public DownloadAppAd mDownloadAppAd;
    public ForumPostData mForumPostData;

    public CommentWrapper() {
        this.e = 0;
    }

    public static CommentWrapper fromComment(Comment comment) {
        CommentWrapper commentWrapper;
        if (comment == null) {
            commentWrapper = null;
        } else {
            commentWrapper = new CommentWrapper();
            commentWrapper.cellType = 1;
            commentWrapper.mComment = comment;
            commentWrapper.id = comment.commentId;
        }
        return commentWrapper;
    }

    public static CommentWrapper extractFromJO(JSONObject jsonObject) {
        if (jsonObject == null) {
            Logger.throwException("object is null");
            return null;
        }

        int cellType = jsonObject.optInt("cell_type", 0);
        if (cellType > 0 && cellType <= 3) {
            CommentWrapper commentWrapper;
            switch (cellType) {
                case 1: {
                    try {
                        JSONObject commentJO = jsonObject.getJSONObject("comment");
                        Comment comment = new Comment();
                        comment.initWithJO(commentJO);
                        commentWrapper = new CommentWrapper();
                        commentWrapper.cellType = cellType;
                        commentWrapper.mComment = comment;
                        commentWrapper.id = comment.commentId;
                        return commentWrapper;
                    } catch (JSONException jsonException) {
                        jsonException.printStackTrace();
                    }
                    return null;
                }
                case 2: {
                    try {
                        ForumPostData forumPostData = ForumPostData.extractFromJO(jsonObject.getJSONObject("forum_post"));
                        if (forumPostData == null) {
                            return null;
                        } else {
                            commentWrapper = new CommentWrapper();
                            commentWrapper.cellType = cellType;
                            commentWrapper.mForumPostData = forumPostData;
                            commentWrapper.id = forumPostData.id;
                            return commentWrapper;
                        }
                    } catch (JSONException jsonException) {
                        jsonException.printStackTrace();
                        return null;
                    }
                }
                case 3: {
                    try {
                        JSONObject adJo = jsonObject.getJSONObject("ad");
                        JSONObject taobaosdkJo = adJo.optJSONObject("taobaosdk");
                        if (taobaosdkJo != null && (AppData.getInstance().isTaoBaoSdkEnable())) {
                            TaoBaoSdkAdsData taoBaoSdkAdsData = new TaoBaoSdkAdsData();
                            taoBaoSdkAdsData.initWithJO(taobaosdkJo);
                            if (taoBaoSdkAdsData.isValid()) {
                                commentWrapper = new CommentWrapper();
                                commentWrapper.cellType = cellType;
                                commentWrapper.d = 1;
                                commentWrapper.id = taoBaoSdkAdsData.ad_id;
                                return commentWrapper;
                            }
                        }
                        taobaosdkJo = adJo.optJSONObject("app");
                        if (taobaosdkJo != null) {
                            DownloadAppAd downloadAppAd = new DownloadAppAd(1);
                            downloadAppAd.initWithJO(taobaosdkJo);
                            if (downloadAppAd.isValid()) {
                                commentWrapper = new CommentWrapper();
                                commentWrapper.cellType = cellType;
                                commentWrapper.d = 2;
                                commentWrapper.mDownloadAppAd = downloadAppAd;
                                commentWrapper.id = downloadAppAd.id;
                                return commentWrapper;
                            }
                        }
                        adJo = adJo.optJSONObject("mixed");
                        if (adJo != null) {
                            MixedAdsData v3_4 = new MixedAdsData();
                            v3_4.initWithJO(adJo);
                            if (v3_4.isValid()) {
                                commentWrapper = new CommentWrapper();
                                commentWrapper.cellType = cellType;
                                commentWrapper.d = 3;
                                commentWrapper.mMixedAdsData = v3_4;
                                commentWrapper.id = v3_4.id;
                                return commentWrapper;
                            } else {
                                return null;
                            }
                        } else {
                            return null;
                        }
                    } catch (JSONException jsonException) {
                        jsonException.printStackTrace();
                        return null;
                    }
                }
            }
            return null;
        } else {
            Logger.throwException("error cellType:" + cellType + ";" + jsonObject.toString());
        }
        return null;
    }

    public final boolean equals(Object arg7) {
        boolean v0 = true;
        if (this != arg7) {
            if (arg7 != null && this.getClass() == arg7.getClass()) {
                if (this.cellType != ((CommentWrapper) arg7).cellType) {
                    v0 = false;
                } else if (this.id != ((CommentWrapper) arg7).id) {
                    v0 = false;
                } else {
                }

                return v0;
            }

            v0 = false;
        }

        return v0;
    }
}

